package com.cskaoyan.market.util;

import com.cskaoyan.market.exception.ParameterException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2024/5/20 10:05
 * @Version 1.0
 */
public class ValidationUtils2 {
    public static void validate(BindingResult bindingResult) {
        if(bindingResult.hasErrors()){
            //有出错
            FieldError fieldError = bindingResult.getFieldError();
            String field = fieldError.getField();
            String defaultMessage = fieldError.getDefaultMessage();
            throw new ParameterException(defaultMessage);
        }
    }
}
